﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ZLWeb.WebApiInfrastructure.Filter;
using Swashbuckle.AspNetCore.SwaggerGen;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.JsonPatch.Operations;
using Swashbuckle.AspNetCore.Swagger;
using System.Reflection;

namespace CrmYwDetail.WebApiApplication.App_Start
{
    public class HttpHeaderFilter : IOperationFilter
    {

        public void Apply(Swashbuckle.AspNetCore.Swagger.Operation operation, OperationFilterContext context)
        {
            if (operation.Parameters == null) operation.Parameters = new List<IParameter>();
            bool hasSplitDB= context.ApiDescription.ActionAttributes().Any(tr=>tr is SplitDBAttribute) ;
            //if (isAuthorized && !allowAnonymous)
            //if (allowAnonymous)
            // 头文件需要包含凭证号、凭证类型的
            if (hasSplitDB)
            {
                //注意此处required必须为true,否则将不走SplitDB过程
                operation.Parameters.Add(new NonBodyParameter { Name = "passporttype", In = "header", Description = "凭证类型", Required = true, Type = "string" });
                operation.Parameters.Add(new NonBodyParameter { Name = "passport", In = "header", Description = "凭证号", Required = true, Type = "string" });
            }
        }
  }
}